<?php get_header(); ?>
  <div class="content">
    <div class="reg_wrapper">
      <form method="post" action="player_reg.php" >
        <div class="fields">
            <div class="group">
				<table>
					<tr>
						<td width="76"><input type="checkbox" name="group[]" value="" /></td>
                		<td width="82"><input type="checkbox" name="group[]" value="" /></td>
                		<td width="84"><input type="checkbox" name="group[]" value="" /></td>
                		<td width="86"><input type="checkbox" name="group[]" value="" /></td>
						<td width="100"><input type="checkbox" name="group[]" value="" /></td>
					</tr>
				</table>
            </div>
            <div class="info">
                <div class="photo">&nbsp;</div>
                <div class="desc">
                    <div class="de1">
                        <input type="text" name="name" value="" size="8" maxlength="8" style="width:71px;"/>
                        <input type="text" name="eng_name" value="" size="20" maxlength="20" style="margin-left:66px;" />
                    </div>
                    <div class="de2">
                        <select name="sex" style="width:41px;">
                            <option value="0" selected="selected">&nbsp;&nbsp;</option>
                            <option value="1">男</option>
                            <option value="2">女</option>
                        </select>
                        <input type="text" name="birthday" size="12" readonly="readonly" style="margin-left:80px;" />
                    </div>
                    <div class="de3">
						<table><tr>
                        	<td width="92"><input type="text" name="nation" value="" size="5" maxlength="10" style="width:51px;"/></td>
							<td width="112">
								<select name="province" style="width:70px;" >
									<option value="0" selected="selected">&nbsp;&nbsp;</option>
<?php
	$province = $wpdb->get_results("SELECT * FROM wp_region WHERE parent_id = 1");
	foreach($province as $pro) {
		print('<option value="' . $pro->region_id . '">' . $pro->region_name . '</option>');
	}
?>
								</select>
							</td>
							<td width="100">
								<select name="city" style="width:70px;" >
									<option value="0" selected="selected">&nbsp;&nbsp;</option>
								</select>
							</td>
						</tr></table>
                    </div>
                    <div class="de4"><input type="text" name="school" value="" size="33" maxlength="60" /></div>
                    <div class="de5">
                        <input type="text" name="post" value="" size="25" maxlength="80" />
                        <input type="text" name="postcode" value="" size="6" maxlength="6" style="margin-left:68px;*margin-left:70px;"/>
                    </div>
                    <div class="de6">
                        <input type="text" name="parent" value="" size="10" maxlength="10" />
                        <input type="text" name="phone" value="" size="12" maxlength="18" style="margin-left:90px;*margin-left:80px;"/>
                    </div>
                    <div class="de7">
                        <input type="text" name="idcard" value="" size="13" maxlength="18" style="width:106px;"/>
                        <input type="text" name="email" value="" size="18" maxlength="128" style="margin-left:69px;"/>
                    </div>
                    <div class="de8">
                        <input type="text" name="teacher" value="" size="32" maxlength="60" />
                    </div>
                    <div class="de9">
                        <input type="text" name="hobby" value="" size="36" maxlength="100" />
                    </div>
                    <div class="de10">
                    <input type="image" name="submit" src="<?php bloginfo('stylesheet_directory'); ?>/images/btn_submit.jpg" />
                    <input type="hidden" name="group_id" value="" />
                    </div>
					<div class="de11">
					<p>* 报名前请仔细阅读活动概述中的报名须知！<a href="<?php bloginfo('stylesheet_directory'); ?>/2010_baoming.doc">下载报名表</a></p>
                    <p>* 如果已经报名，可以<a href="<?php bloginfo('url'); ?>/?page_id=205">查询报名信息</a></p>
					</div>
                </div>
            </div>
        </div>
      </form>
    </div>
  </div><!-- content -->
  <script type="text/javascript">
    $().ready(function() {
        $("input[name='birthday']").datepick({maxDate: new Date(), yearRange: 'c-15: c'});
        $("input[type='checkbox']").bind('click', function(e) {
            $("input[type='checkbox']").removeAttr("checked");
            if (!$(this).attr("checked")) {
                $(this).attr("checked", true);
            }
        });
        $("form").bind('submit', form_submit);
		$("select[name='province']").bind('change', function(){
			var pro_id = $(this).attr("value");
			$.get("player_reg.php", {act: "city", id: pro_id},
				function(ret) {
					var str = ret.replace(/<\\/g, '<');
					$("select[name='city']").html(str);
				}, "html");
		});
		/*
		$("input[name='idcard']").bind('keyup', function() {
			this.value = this.value.replace(/[^\dxX]/g, '');
	});*/
		$("input[name='phone']").bind('keyup', function() {
			this.value = this.value.replace(/[^\d\-]/g, '');
		});
		$("input[name='postcode']").bind('keyup', function() {
			this.value = this.value.replace(/[^\d]/g, '');
		});
    });

    function form_submit() {
        var error = false;
		var error_msg = '';
		var error_blank = false;
		var msg_blank = "请完整填写报名信息，所有字段都是必填项。";
        var group_id = -1;
        $("input[type='checkbox']").each(function(i) {
            if ($(this).attr("checked") == true) {
                group_id = i + 1;
            }
        });
        $("input[name='group_id']").attr("value", group_id);

		if (!$("input[name='name']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='eng_name']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if ($("select[name='sex']").attr("value") == 0) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='birthday']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='nation']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if ($("select[name='province']").attr("value") == 0) {
			error = true;
			error_blank = true;
		}
		if ($("select[name='city']").attr("value") == 0) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='school']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='post']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='postcode']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='parent']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='phone']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='idcard']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='email']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='teacher']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (!$("input[name='hobby']").attr("value")) {
			error = true;
			error_blank = true;
		}
		if (group_id == -1) {
			error = true;
			error_blank = true;
		}
		if ($("input[name='postcode']").attr("value").length != 6) {
			error = true;
			error_msg = error_msg + "\n" + "邮政编码格式不正确。";
		}
		var idcard = $("input[name='idcard']").attr("value");
		if (idcard.length != 15 && idcard.length != 18 && !idcard.match(/^(\d{15}|\d{17}[\dxX])$/)) {
			error = true;
			error_msg = error_msg + "\n" + "身份证号码格式不正确。";
		}
		var email = $("input[name='email']").attr("value");
		if (!email.match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)) {
			error = true;
			error_msg = error_msg + "\n" + "电子信箱格式不正确。";
		}
		if (error_blank) error_msg = msg_blank +  error_msg;
        if (error) {
            alert(error_msg);
            return false;
        }
        return true;
    }
  </script>
<?php get_footer(); ?>
